# 用户类 作为父类主要有用户名、密码、姓名、性别、年龄、电话、地址 并且实现getter和setter方法。
class User():
    def __init__(self, user_name, pass_word, name, sex, age, phone, address):
        self._username = user_name
        self._password = pass_word
        self._name = name
        self._sex = sex
        self._age = age
        self._phone = phone
        self._address = address

    # 生成相关的getter,setter方法
    @property
    def username(self):
        return self._username

    @username.setter
    def username(self, value):
        if not isinstance(value, str):
            raise ValueError("用户名必须是字符串")
        self._username = value

    @property
    def password(self):
        return self._password

    @password.setter
    def password(self, value):
        if not isinstance(value, str):
            raise ValueError("密码必须是字符串")
        self._password = value

    @property
    def name(self):
        return self._name

    @name.setter
    def name(self, value):
        if not isinstance(value, str):
            raise ValueError("姓名必须是字符串")
        self._name = value

    @property
    def sex(self):
        return self._sex

    @sex.setter
    def sex(self, value):
        if not isinstance(value, str):
            raise ValueError("性别必须是字符串")
        self._sex = value

    @property
    def age(self):
        return self._age

    @age.setter
    def age(self, value):
        if not isinstance(value, int) or value < 0:
            raise ValueError("年龄必须大于0且必须是整数")
        self._age = value

    @property
    def phone(self):
        return self._phone

    @phone.setter
    def phone(self, value):
        if not isinstance(value, int):
            raise ValueError("手机号必须是数字")
        self._phone = value

    @property
    def address(self):
        return self._address

    @address.setter
    def address(self, value):
        if not isinstance(value, str):
            raise ValueError("地址必须是字符串")
        self._address = value

    # 重写
    def toString(self):
        # 为什么输出有括号。

        return '用户名:' + self.username + '\n密码:' + self.password + '用户姓名:' + self.name, '\n用户性别:' + self.sex, '\n用户年龄:' + self.age, '\n用户电话:' + self.phone, '\n用户地址:' + self.address
        # return "用户姓名:" + self.name + '\n用户性别:' + self.sex + '\n用户年龄:' + self.age + '\n用户电话:' + self.phone + '\n用户地址:' + self.address


# # 使用示例
# person = Users("Alice", '男', age=None, address=None, phone=None)
#
# # 获取属性
# print(person.name)  # 输出: Alice
# print(person.age)  # 输出: 30
# print(person.sex)
# # 设置属性
# person.name = "Bob"
# person.age = 35
# person.sex=0
# print(person.name)  # 输出: Bob
# print(person.age)  # 输出: 35
# print(person.sex)
#
# # 尝试设置无效值
# try:
#     person.age = -5
# except ValueError as e:
#     print(e)  # 输出: 年龄必须大于0且必须是整数
# try:
#     person.sex = 3
# except ValueError as e:
#     print(e)

# us = User("小名", "男", '20', '12345679', "123123123")
# print(us.toString())
